import request from '@/utils/request'

/**
 * 获取所有角色列表
 */
export const reqGetRoleList = (page, pagesize) => {
  return request({
    method: 'get',
    url: '/sys/role',
    params: {
      page,
      pagesize
    }
  })
}

/**
 * 根据id删除角色
 */
export const reqDelRole = id => {
  return request({
    method: 'delete',
    url: `/sys/role/${id}`
  })
}

/**
 * 添加角色
 */
export const reqAddRole = (form) => {
  return request({
    method: 'post',
    url: '/sys/role',
    data: form
  })
}

/**
 *  根据id获取角色详情
 */
export const reqGetRoleDetail = id => {
  return request({
    method: 'get',
    url: `/sys/role/${id}`
  })
}

/**
 * 根据ID更新角色
 */
export const reqUpdateRole = form => {
  return request({
    method: 'put',
    url: `/sys/role/${form.id}`,
    data: form
  })
}

/**
 * 根据角色id分配权限
 * @param {*} id 角色id
 * @param {*} permIds 权限id的数组
 */
export const reqAssignPermission = (id, permIds) => {
  return request({
    method: 'put',
    url: '/sys/role/assignPrem',
    data: {
      id,
      permIds
    }
  })
}

